#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>


struct in_addr        localInterface;
struct sockaddr_in    groupSock;
int                   sd;
int                   datalen;

void sleep() {
	float b = 1.1;
	int j;
	float c;
	for (j = 0; j<655555; j++) {
		b = b * b;
	}
}

int main (int argc, char *argv[])
{
	char databuf[12][8];
	strcpy(databuf[0],  "*......");
	strcpy(databuf[1],  ".*.....");
	strcpy(databuf[2],  "..*....");
	strcpy(databuf[3],  "...*...");
	strcpy(databuf[4],  "....*..");
	strcpy(databuf[5],  ".....*.");
	strcpy(databuf[6],  "......*");
	strcpy(databuf[7],  ".....*.");
	strcpy(databuf[8],  "....*..");
	strcpy(databuf[9],  "...*...");
	strcpy(databuf[10], "..*....");
	strcpy(databuf[11], ".*.....");

	/* ------------------------------------------------------------*/
	/*                                                             */
	/* Send Multicast Datagram code example.                       */
	/*                                                             */
	/* ------------------------------------------------------------*/

/*
	* Create a datagram socket on which to send.
*/
	sd = socket(AF_INET, SOCK_DGRAM, 0);
	if (sd < 0) {
		perror("opening datagram socket");
		exit(1);
	}

/*
	* Initialize the group sockaddr structure with a
	* group address of 230.0.0.1 and port 4446.
*/
	memset((char *) &groupSock, 0, sizeof(groupSock));
	groupSock.sin_family = AF_INET;
	groupSock.sin_addr.s_addr = inet_addr("230.0.0.1");
	groupSock.sin_port = htons(4446);

/*
	* Send a message to the multicast group specified by the
	* groupSock sockaddr structure.
*/

	datalen = 7;
	int i;
	while (1) {
		for (i=0; i<12; i++) {
			int abc = sendto(sd, databuf[i], datalen, 0, (struct sockaddr*)&groupSock,sizeof(groupSock));
			printf("enviados: %d bytes: %s\n", abc,databuf[i]);
			
			sleep();
		}
	}
}

